# SPDX-License-Identifier: GPL-2.0
#
# Makefile for the linux kernel.
#
ccflags-$(CONFIG_RTOS_KERNEL_BUILD_CC_OPIMIZE) += -O2
obj-y     = fork.o exec_domain.o panic.o \
	    cpu.o exit.o softirq.o resource.o \
	    sysctl.o capability.o ptrace.o user.o \
	    signal.o sys.o umh.o workqueue.o pid.o task_work.o \
	    extable.o params.o \
	    kthread.o sys_ni.o nsproxy.o \
	    notifier.o ksysfs.o cred.o reboot.o \
	    async.o range.o smpboot.o ucount.o regset.o

obj-$(CONFIG_EULEROS_TASK_EXIT_NOTIFIER_CHAIN) += task_exit_notifier.o
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o
obj-$(CONFIG_MODULES) += kmod.o
obj-$(CONFIG_MULTIUSER) += groups.o
obj-$(CONFIG_EULEROS_KERNEL_FAULT_NOTIFIER) += kernel_fault_notifier.o
obj-$(CONFIG_RTOS) += rtos_fork.o
obj-$(CONFIG_RTOS) += rtos_sysctl.o
obj-$(CONFIG_RTOS) += rtos_sec.o
obj-$(CONFIG_RTOS) += rtos_tracepoint.o
obj-$(CONFIG_EULEROS_FAST_CORE_DOWN) += euelros_fast_core_down.o
obj-$(CONFIG_RTOS_SWIFT_IRQSOFF) += swift_irqsoff.o
obj-$(CONFIG_RTOS_EXTRACT_KALLSYMS) += rtos/rtos_kallsyms/extract_kallsyms.o
obj-$(CONFIG_RTOS_STRICT_DEVMEM_IOMEM_CONTROL) += rtos/strict_devmem.o
obj-$(CONFIG_TASK_STRUCT_EXTEND) += task_struct_extend.o
obj-$(CONFIG_RTOS_IDUMP_FORCE) += idump_signal.o
obj-$(CONFIG_RTOS_IDUMP_TRIGGER) += idump_signal.o
obj-$(CONFIG_RTOS_KBOX) += kbox/
obj-$(CONFIG_RTOS_KBOX) += set_kbox_region.o
obj-$(CONFIG_RTOS_DEBUG_SOFTLOCKUP) += rtos_softlockup.o
obj-$(CONFIG_RTOS_DEBUG_SOFTLOCKUP_GRADING) += rtos_softlockup_grading.o
obj-$(CONFIG_RTOS_PREEMPT_OFF) += rtos_preempt_off.o
obj-$(CONFIG_RTOS_TASKLOCK) += tasklock.o
obj-$(CONFIG_RTOS_DYN_RES_MEMORY) += dynmem/
obj-$(CONFIG_RTOS_PPC_REMOVE_DCBZ) += rtos/remove_dcbz.o
obj-$(CONFIG_RTOS) += rtos_tracepoint.o
obj-$(CONFIG_RTOS_STACK_REPEAT_CHECK) += stackrepeatcheck.o
obj-$(CONFIG_RTOS_MICROSTATE_ACCT) += msa.o
obj-$(CONFIG_RTOS_FIND_TRUSTLIST_SYMBOLS) += rtos/find_trustlist_symbols.o
$(obj)/rtos/find_trustlist_symbols.o: gen_trustlist
quiet_cmd_gen_trustlist = GEN     rtos_trustlist
      cmd_gen_trustlist = $(CONFIG_SHELL) $(srctree)/scripts/add_trustlist_sym.sh -o $(CONFIG_RTOS_TRUSTLIST_SYMBOLS)
gen_trustlist: FORCE
	$(call cmd,gen_trustlist)
obj-$(CONFIG_RTOS_DEBUG_DUMP_AROUND_REGISTER_MEM) += oops_enhance.o
obj-$(CONFIG_RTOS_DEBUG_MEMDUMP) += rtos_dump.o
obj-$(CONFIG_RTOS_DEBUG_EXCEPTION_ENHANCE) += rtos_exception_enhance.o
obj-$(CONFIG_RTOS_DEBUG_EXCEPTION_ENHANCE) += rtos_undefinstr_enhance_filter.o
obj-$(CONFIG_RTOS_DEBUG_UNDEFINSTR_ENHANCE) += rtos_undefinstr_enhance_filter.o
obj-$(CONFIG_RTOS_HUNGTASK_TIMES) += rtos_hung_task.o
obj-$(CONFIG_RTOS_SUPPORT_PRIVATE_HUNGTASK) += rtos_hung_task.o
obj-$(CONFIG_RTOS_IMPROVE_PERF_USER_BACKTRACE) += rtos_perf_user_backtrace.o
obj-$(CONFIG_RTOS_KEXEC_HARDENING) += rtos_kexec_hardening.o
obj-$(CONFIG_RTOS_HAL_KEXEC_CMDLINE_PROCESS) += rtos_kexec.o
obj-$(CONFIG_EULEROS_CPU_STAT_AND_IRQ) += cpustat.o
obj-$(CONFIG_EULEROS_KBOX_ADD_PRINTK_NOTIFIER) += os_kbox.o
obj-$(CONFIG_RTOS_HP_OBTAIN_STAT) += rtos_hpstat.o
obj-$(CONFIG_EULEROS_SYSMONITOR_SIGNAL) += sysmonitor-signal.o
obj-$(CONFIG_RTOS_DEBUG_SIGFRAME_FAIL_INFO) += rtos_signal.o

ifdef CONFIG_FUNCTION_TRACER
# Do not trace internal ftrace files
CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE)
endif

# Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip()
# in coverage traces.
KCOV_INSTRUMENT_softirq.o := n
# Avoid KCSAN instrumentation in softirq ("No shared variables, all the data
# are CPU local" => assume no data races), to reduce overhead in interrupts.
KCSAN_SANITIZE_softirq.o = n
# These are called from save_stack_trace() on slub debug path,
# and produce insane amounts of uninteresting coverage.
KCOV_INSTRUMENT_module.o := n
KCOV_INSTRUMENT_extable.o := n
KCOV_INSTRUMENT_stacktrace.o := n
# Don't self-instrument.
KCOV_INSTRUMENT_kcov.o := n
KASAN_SANITIZE_kcov.o := n
KCSAN_SANITIZE_kcov.o := n
CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector

# Don't profile module.c:
# CLANG_PGO changes the layout of struct module
# for instrumented kernel so the profile data
# will mismatch on final build.
PGO_PROFILE_module.o := n

obj-y += sched/
obj-y += locking/
obj-y += power/
obj-y += printk/
obj-y += irq/
obj-y += rcu/
obj-y += livepatch/
obj-y += dma/
obj-y += entry/

obj-$(CONFIG_KCMP) += kcmp.o
obj-$(CONFIG_FREEZER) += freezer.o
obj-$(CONFIG_PROFILING) += profile.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
obj-y += time/
obj-$(CONFIG_FUTEX) += futex/
obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
obj-$(CONFIG_SMP) += smp.o
ifneq ($(CONFIG_SMP),y)
obj-y += up.o
endif
obj-$(CONFIG_UID16) += uid16.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_MODULE_SIG) += module_signing.o
obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o
obj-$(CONFIG_KALLSYMS) += kallsyms.o
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
obj-$(CONFIG_CRASH_CORE) += crash_core.o
obj-$(CONFIG_EULEROS_CRASH_AUTO) += crash_auto.o
obj-$(CONFIG_KEXEC_CORE) += kexec_core.o
obj-$(CONFIG_KEXEC) += kexec.o
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o
obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o
obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
obj-$(CONFIG_COMPAT) += compat.o
obj-$(CONFIG_CGROUPS) += cgroup/
obj-$(CONFIG_UTS_NS) += utsname.o
obj-$(CONFIG_USER_NS) += user_namespace.o
obj-$(CONFIG_PID_NS) += pid_namespace.o
obj-$(CONFIG_IKCONFIG) += configs.o
obj-$(CONFIG_IKHEADERS) += kheaders.o
obj-$(CONFIG_SMP) += stop_machine.o
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
obj-$(CONFIG_AUDITSYSCALL) += auditsc.o audit_watch.o audit_fsnotify.o audit_tree.o
obj-$(CONFIG_RTOS_AUDIT_CPU_AFFINITY) += rtos/rtos_audit_affinity.o
obj-$(CONFIG_GCOV_KERNEL) += gcov/
obj-$(CONFIG_KCOV) += kcov.o
obj-$(CONFIG_KPROBES) += kprobes.o
obj-$(CONFIG_FAIL_FUNCTION) += fail_function.o
obj-$(CONFIG_KGDB) += debug/
obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
obj-$(CONFIG_HARDLOCKUP_DETECTOR) += watchdog_hld.o
obj-$(CONFIG_EULEROS_WATCHDOG_ENHANCE_FEATRUE) += watchdog_enhance.o
obj-$(CONFIG_SECCOMP) += seccomp.o
obj-$(CONFIG_RELAY) += relay.o
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
obj-$(CONFIG_LATENCYTOP) += latencytop.o
obj-$(CONFIG_FUNCTION_TRACER) += trace/
obj-$(CONFIG_TRACING) += trace/
obj-$(CONFIG_TRACE_CLOCK) += trace/
obj-$(CONFIG_RING_BUFFER) += trace/
obj-$(CONFIG_TRACEPOINTS) += trace/
obj-$(CONFIG_IRQ_WORK) += irq_work.o
obj-$(CONFIG_CPU_PM) += cpu_pm.o
obj-$(CONFIG_BPF) += bpf/
obj-$(CONFIG_KCSAN) += kcsan/
obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
obj-$(CONFIG_PGO_CLANG) += pgo/
obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o

obj-$(CONFIG_PERF_EVENTS) += events/

obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
obj-$(CONFIG_PADATA) += padata.o
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
obj-$(CONFIG_TORTURE_TEST) += torture.o

obj-$(CONFIG_HAS_IOMEM) += iomem.o
obj-$(CONFIG_RSEQ) += rseq.o
obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o

obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o

# security
ifeq ($(CONFIG_RTOS),y)
obj-$(CONFIG_MODULE_CERT_MANAGE) += kernel_cert_manage.o
obj-$(CONFIG_RTOS_MODULE_CERT_REVOCATE) += kernel_cert_revocate.o
ccflags-$(CONFIG_RTOS_SUPPORT_CMS_CBB) += -Isecurity/rtos/cms_cbb/include
endif

# vnotify fast svc
ifeq ($(CONFIG_RTOS),y)
obj-$(CONFIG_RTOS_HAL_FAST_SVC)		+= rtos_fast_svc.o
endif

ifeq ($(CONFIG_EULEROS_SIGNATURE_PSS),y)
obj-y += kernel_cert_manage.o
obj-y += kernel_cert_revocate.o
ccflags-y += -Isecurity/euler/cms_cbb/include
endif

CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN)
obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
KASAN_SANITIZE_stackleak.o := n
KCSAN_SANITIZE_stackleak.o := n
KCOV_INSTRUMENT_stackleak.o := n

obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o

CFLAGS_REMOVE_hkrr.o = -pg
CFLAGS_REMOVE_hkrr_utils.o = -pg

obj-$(CONFIG_RTOS_ISOLATION_VM) += rtos_isolation_vm.o

obj-$(CONFIG_RTOS_HKRR) += hkrr.o hkrr_utils.o hkrr_table.o
KASAN_SANITIZE_hkrr.o := n
KASAN_SANITIZE_hkrr_utils.o := n
KCOV_INSTRUMENT_hkrr.o := n
KCOV_INSTRUMENT_hkrr_utils.o := n

# merge high-precision timer can reduce interrupts and context switches
obj-$(CONFIG_EULEROS_MERGE_TIMER_IRQ)	+= cpu_high_precision.o

obj-$(CONFIG_EULEROS_HUNGTASK_DEBUG) += euleros_hungtask.o

$(obj)/configs.o: $(obj)/config_data.gz

targets += config_data config_data.gz
$(obj)/config_data.gz: $(obj)/config_data FORCE
	$(call if_changed,gzip)

filechk_cat = cat $<

$(obj)/config_data: $(KCONFIG_CONFIG) FORCE
	$(call filechk,cat)

$(obj)/kheaders.o: $(obj)/kheaders_data.tar.xz

quiet_cmd_genikh = CHK     $(obj)/kheaders_data.tar.xz
      cmd_genikh = $(CONFIG_SHELL) $(srctree)/kernel/gen_kheaders.sh $@
$(obj)/kheaders_data.tar.xz: FORCE
	$(call cmd,genikh)

clean-files := kheaders_data.tar.xz kheaders.md5
